﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Main.Master" Inherits="System.Web.Mvc.ViewPage<QuanLyNhaThuoc.Models.AdminModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <!-- iCheck for checkboxes and radio inputs -->
    <link href="/Content/themes/Pharma/iCheck/minimal/blue.css" rel="stylesheet" type="text/css" />
    <link href="/Content/themes/Loading/waiting.css" rel="stylesheet" type="text/css" />

    <!-- MAILBOX BEGIN -->
    <div class="mailbox row">
        <div class="col-xs-12">
            <div class="box box-solid">
                <div class="box-body">
                    <div class="row"> <div class="col-md-12 col-sm-12">
                    <table cellpadding="5"><tr><td>
                       
                            Công ty</td><td>
                        <!-- compose message btn -->
                        <%:Html.DropDownListFor(m => m.CorpList, Model.CorpList, new {@class="select-default",@id="ddlCorp"})%>
                        
                        </td></tr></table></div>
                    </div>
                
                <div class="row">
                    <div class="col-md-3 col-sm-4">
                        <!-- BOXES are complex enough to move the .box-header around.
                                                 This is an example of having the box header within the box body -->
                        <!-- Navigation - folders-->
                        <div style="margin-top: 15px;">
                            <ul class="nav nav-pills nav-stacked" id="lstGroup">
                                <li class="header">Nhóm người dùng</li>                                
                                <% foreach (var item in Model.GroupList.ToList())
                                   { %>
                                <li><a id="<%: item.GroupID %>" href="#" class="aa"><i class="glyphicon glyphicon-user"></i><%: item.GroupName %></a></li>
                                <%} %>
                               
                               
                            </ul>
                        </div>
                    </div>
                    <!-- /.col (LEFT) -->
                    <div class="col-md-9 col-sm-8">
                        <div class="row pad">
                            <div class="col-sm-6">
                            </div>
                            <div class="col-sm-6 search-form">
                                <form action="#" class="text-right">
                                <div class="input-group">
                                </div>
                                </form>
                            </div>
                        </div>
                        <!-- /.row -->
                        <div class="table-responsive">
                            <!-- THE MESSAGES -->
                            <div id="tabs-1">
                                <ul id="tvRole">
                                    <%:Html.Raw(Model.MenuString) %>
                                </ul>
                            </div>
                        </div>
                        <!-- /.table-responsive -->
                    </div>
                    <!-- /.col (RIGHT) -->
                </div>
                <!-- /.row -->
            </div>
            <!-- /.box-body -->
            <div class="box-footer clearfix">
                                    <div class="pull-right">                                       
                                        <div class="form-group">
                    <div class="btn-toolbar">
                        <button class="btn btn-default" id="btnSave">
                            Lưu quyền</button>
                        <button class="btn btn-default" id="btnReset">
                            Khởi tạo</button>
                    </div>
                </div>
                                    </div>
                                </div><!-- box-footer -->
            </div>
            <!-- /.box -->
        </div>
        <!-- /.col (MAIN) -->
    </div>
    <!-- MAILBOX END -->
    <div id="groupID" style="visibility:hidden"></div>
    <!-- jQuery 1.8.3 -->
    <script src="http://code.jquery.com/jquery-1.8.3.min.js" type="text/javascript"></script>
    <!-- Bootstrap -->
    <script src="/Scripts/Pharma/bootstrap.min.js" type="text/javascript"></script>
    <!-- Bootstrap WYSIHTML5 -->
    <script src="/Scripts/Pharma/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js"
        type="text/javascript"></script>
    <!-- Page script -->
    <script type="text/javascript">
        $("#tvAdmin").addClass("active");
        $("#ulAdmin").attr("style", "display:block");
        $("#liPermission").addClass("active");
        
    </script>
    <!-- start checkboxTree configuration -->
    <script type="text/javascript" src="/Scripts/CheckboxTree/jquery-ui-1.8.12.custom.min.js"></script>
    <link rel="stylesheet" type="text/css" href="/Content/themes/CheckBoxTree/jquery-ui-1.8.12.custom.css" />
    <script type="text/javascript" src="/Scripts/CheckboxTree/jquery.checkboxtree.js"></script>
    <link rel="stylesheet" type="text/css" href="/Content/themes/CheckBoxTree/jquery.checkboxtree.css" />
    <!-- end checkboxTree configuration -->
    <script type="text/javascript" src="/Scripts/CheckboxTree/jquery.cookie.js"></script>
    <script type="text/javascript">
        $('#tvRole').checkboxTree();
        //<!--
        $(document).ready(function () {
            $('#tabs').tabs({
                cookie: { expires: 30 }
            });
            $('.jquery').each(function () {
                eval($(this).html());
            });
            $('.button').button();
        });
        //-->
    </script>
    <!-- AdminLTE App -->
    <script src="/Scripts/Pharma/AdminLTE/app_permission.js" type="text/javascript"></script>
    <script src="/Scripts/Pharma/plugins/notification/jquery.noty.packaged.min.js"
        type="text/javascript"></script>
    <script src="/Scripts/Pharma/plugins/notification/Notification.js" type="text/javascript"></script>
    <script src="/Scripts/Loading/jquery.waiting.js" type="text/javascript"></script>

   
    <script type="text/javascript">
        $(function () {
            $("select#ddlCorp").change(function (evt) {               
                $("#groupID").val("");
                $("input:checkbox:checked").removeAttr("checked");

                $.ajax({
                    url: "/Admin/ChangeCorp",
                    type: 'POST',
                    data: { id: $("select#ddlCorp").val() },
                    success: function (response) {
                        $("ul#lstGroup").replaceWith(response); 

                        $(function () {
                            $("a.aa").click(function (evt) {
                                $("a.aa").parent().removeClass("active");
                                $(this).parent().addClass("active");
                                                               
                            });
                        });
                    },
                    error: function (xhr) {
                        var n = noty({ layout: 'topCenter', text: response, type: 'error', timeout: 2000 });
                    }
                });
            });
        });
</script>


<script type="text/javascript">
    $(function () {
        $("a.aa").click(function (evt) {
            $("a.aa").parent().removeClass("active");
            $(this).parent().addClass("active");
            $("#groupID").val($(this).attr("id"));            

            $.ajax({
                url: "/Admin/LoadMenuOfGroup",
                type: 'POST',
                data: { id: $(this).attr("id") },
                success: function (response) {
                    $("ul#tvRole").replaceWith(response);                            
                },
                error: function (xhr) {
                    var n = noty({ layout: 'topCenter', text: response, type: 'error', timeout: 2000 });
                }
            });
        });
    });
</script>

<script type="text/javascript">
    $("#btnSave").click(function (evt) {
        if ($("#groupID").val() == "") {
            var n = noty({ layout: 'topCenter', text: 'Vui lòng chọn nhóm người dùng', type: 'error', timeout: 2000 });
            return;
        }

        var FMID = "";
        $.each($("input:checkbox:checked"), function (index, value) {
            FMID = FMID + "#" + $(value).attr("id");
        });

        $.ajax({
            url: "/Admin/Save",
            type: 'POST',
            data: { fmid: FMID, groupid: $("#groupID").val() },
            success: function (response) {
                var n = noty({ layout: 'topCenter', text: response, type: 'success', timeout: 2000 });

            },
            error: function (xhr) {
                var n = noty({ layout: 'topCenter', text: response, type: 'error', timeout: 2000 });
            }
        });
    });
</script>

<script type="text/javascript">
    $("#btnReset").click(function (evt) {
        $("input:checkbox:checked").removeAttr("checked");
        var n = noty({ layout: 'topCenter', text: 'Khởi tạo quyền thành công', type: 'success', timeout: 2000 });
    }
    );
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="head" runat="server">
    <%:ViewBag.Title %>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="NavBar" runat="server">
    <h1>
        Phân quyền ứng dụng <small>Control panel</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i>Home</a></li>
        <li class="active">Quản trị hệ thống</li>
        <li class="active">Phân quyền ứng dụng</li>
    </ol>
</asp:Content>
